﻿/*code dialog*/
CKEDITOR.dialog
		.add(
				'codeDialog',
				function(editor) {
					return {
						title : "插入 code",
						minWidth : 500,
						minHeight : 300,
						contents : [ {
							id : 'code_panel',
							elements : [
									{
										id : "codeType",
										label : "选择语言",
										labelStyle : "margin:5px 0px;display:block",
										type : "select",
										items : [ [ 'Actionscript3.0', 'as' ],
												[ 'C', 'c' ], [ 'C++', "cc" ],
												[ 'Html', 'html' ],
												[ 'Java', 'java' ],
												[ 'Javascript', 'js' ],
												[ 'Php' ], [ 'Net' ],
												[ 'Shell', 'sh' ],
												[ 'Xml', 'xml' ] ],
										inputStyle : "width:200px"
									},
									{
										id : "codeContent",
										label : "你的代码",
										labelStyle : "margin:5px 0px;display:block",
										type : "textarea",
										rows : 15,
										inputStyle : "font-family:Verdana,Arial,Helvetica,sans-serif"
									} ]
						} ],
						/* google-code-prettify */
						onOk : function() {
							var code = this
									.getValueOf("code_panel", "codeType");
							var content = this.getValueOf("code_panel",
									"codeContent");
							var html = escapeHTML(content);
							editor
									.insertHtml("<pre class=\"prettyprint linenums lang-"
											+ code + "\">"
											// + code
											+ html + "</pre>");
						}
					};
				});

function escapeHTML(content) {
	return content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g,
			'&gt;');
}

function unescapeHtml(original) {
	return original.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(
			/&quot;/g, '"').replace(/&#039;/g, "'").replace(/&amp;/g, '&');
};
